#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 4e4+10;

typedef long long ll;

struct line{
	int x1,x2,y,v;
	bool operator < (const line &b)const{
		return y ^ b.y ? y < b.y : v < b.v;
	}
}l[MAXN];

int a[MAXN],cnt,n,w,h;
ll ans,val[MAXN<<2],lz[MAXN<<2];

#define in read()

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1) + (x<<3) + (ch^48);
	return x*sgn;
}

void pushdown(int o){
	if(lz[o] != 0){
		val[o<<1] += lz[o]; val[o<<1|1] += lz[o];
		 lz[o<<1] += lz[o];  lz[o<<1|1] += lz[o];
		lz[o] = 0;
	}
}

void upd(int xl,int xr,int v,int o = 1,int l = 1,int r = cnt){
	if(xl == l && xr == r){
		val[o] += v; lz[o] += v;
		return;
	}
	pushdown(o);
	int mid = l+r>>1;
	if(xr <= mid) upd(xl,xr,v,o<<1,l,mid);
	else if(xl > mid) upd(xl,xr,v,o<<1|1,mid+1,r);
	else upd(xl,mid,v,o<<1,l,mid),upd(mid+1,xr,v,o<<1|1,mid+1,r);
	val[o] = max(val[o<<1],val[o<<1|1]);
}

int main (){
	int T = in;
	while(T--){
		n = in,cnt = 0;w = in - 1,h = in;ans = 0;
		memset(val,0,sizeof(val)); memset(lz,0,sizeof(lz));
		for(int i = 1;i <= n;i++){
			int x = in,y = in,li = in;
			a[(i<<1)-1] = x,a[i<<1] = x+w;
			l[(i<<1)-1] = line{x,x+w,y,li};
			l[i<<1] = line{x,x+w,y+h,-li};
		}
		n<<=1;
		sort(a+1,a+n+1);
		cnt = unique(a+1,a+n+1) - a - 1;
		sort(l+1,l+n+1);
		for(int i = 1;i <= n;i++){
			l[i].x1 = lower_bound(a+1,a+cnt+1,l[i].x1)-a;
			l[i].x2 = lower_bound(a+1,a+cnt+1,l[i].x2)-a;
			upd(l[i].x1,l[i].x2,l[i].v);
			ans = max(ans,val[1]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}
